Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | inji.Chats = {}; |
||
70 | inji.Chats.init = function (chatIndex) { |
||
71 | var updater = function () { |
||
72 | inji.Server.request({ |
||
73 | url: 'chats/events/' + inji.Chats.chats[chatIndex].chatId, |
||
74 | data: { |
||
75 | lastEventDate: inji.Chats.chats[chatIndex].lastEventDate |
||
76 | }, |
||
77 | success: function (data) { |
||
78 | inji.Chats.chats[chatIndex].members = data.members; |
||
79 | inji.Chats.chats[chatIndex].checkoutMembers(); |
||
80 | for (key in data.messages) { |
||
81 | var msg = data.messages[key]; |
||
82 | inji.Chats.chats[chatIndex].lastEventDate = msg.message.chat_message_date_create; |
||
83 | var template = inji.Chats.chats[chatIndex].element.find('.chats-chat-message-template').html(); |
||
84 | template = template.replace(/message-id/g, msg.message.chat_message_id); |
||
85 | template = template.replace(/message-userId/g, msg.message.chat_message_user_id); |
||
86 | template = template.replace(/message-date_create/g, msg.message.chat_message_date_create); |
||
87 | template = template.replace(/user-firstName/g, msg.userFirstName); |
||
88 | template = template.replace(/user-fullName/g, msg.fullUserName); |
||
89 | template = template.replace(/user-photo/g, msg.userPhoto); |
||
90 | template = template.replace(/message-text/g, msg.message.chat_message_text); |
||
91 | var messageList = inji.Chats.chats[chatIndex].element.find('.chats-chat-messageList'); |
||
92 | if (inji.Chats.chats[chatIndex].reverse) { |
||
93 | messageList.append(template); |
||
94 | if (inji.Chats.chats[chatIndex].scrollable) { |
||
95 | var height = messageList.height() + messageList.scrollTop() + parseInt(messageList.css('paddingTop')) + parseInt(messageList.css('paddingBottom')); |
||
96 | messageList.scrollTop(messageList[0].scrollHeight); |
||
97 | } |
||
98 | } else { |
||
99 | messageList.prepend(template); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | var allMsgs = inji.Chats.chats[chatIndex].element.find('.chats-chat-messageList>*'); |
||
104 | if (allMsgs.length > 20) { |
||
105 | var i = 0; |
||
106 | if (inji.Chats.chats[chatIndex].reverse) { |
||
107 | var diff = allMsgs.length - 20; |
||
108 | while (i <= diff && i >= 0) { |
||
109 | $(allMsgs[i]).remove(); |
||
110 | i--; |
||
111 | } |
||
112 | } else { |
||
113 | i = allMsgs.length + 1; |
||
114 | while (i > 20 && allMsgs[i]) { |
||
115 | $(allMsgs[i]).remove(); |
||
116 | i++; |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | }); |
||
122 | }; |
||
123 | updater(); |
||
124 | inji.Chats.chats[chatIndex].timer = setInterval(updater, 5000); |
||
125 | } |
||
126 | inji.Chats.sendForm = function (form, id) { |
||
135 | } |